package com.xuelang.pipeline.entry.resource;

import com.xuelang.pipeline.app.resource.EnvironmentService;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.resource.IEnvironmentService;
import com.xuelang.pipeline.client.resource.dto.EnvironmentDTO;
import com.xuelang.pipeline.client.resource.dto.EnvironmentQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 环境服务web控制类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Slf4j
@RestController
@RequestMapping("/environment")
public class EnvironmentController  implements IEnvironmentService {

    @Autowired
    private EnvironmentService environmentService;

    @Override
    public ApiResult<PageRecord<EnvironmentDTO>> pageEnvironmentList(PageParam<EnvironmentQuery> dtoPageParam) {
        return ApiResult.success(environmentService.pageList(dtoPageParam));
    }

    @Override
    public ApiResult<List<EnvironmentDTO>> conditionalEnvironmentList(EnvironmentQuery environmentQuery) {
        return ApiResult.success(environmentService.list(environmentQuery));
    }

    @Override
    public ApiResult<List<EnvironmentDTO>> listEnvironmentByKeyword(String keyword) {
        return ApiResult.success(environmentService.list(EnvironmentQuery.builder().name(keyword).build()));
    }

    @Override
    public ApiResult<Boolean> addEnvironment(EnvironmentDTO environmentDTO) {
        return ApiResult.success(environmentService.add(environmentDTO));
    }

    @Override
    public ApiResult<Boolean> updateEnvironment(EnvironmentDTO environmentDTO) {
        return ApiResult.success(environmentService.update(environmentDTO));
    }

    @Override
    public ApiResult<Boolean> deleteEnvironment(String uuid) {
        return ApiResult.success(environmentService.delete(uuid));
    }

    @Override
    public ApiResult<Boolean> existsPipelineByEnvironment(String environmentUuid) {
        return ApiResult.success(environmentService.existsPipelineByEnvironment(environmentUuid));
    }

    @Override
    public ApiResult<EnvironmentDTO> queryEnvironment(String uuid) {
        return ApiResult.success(environmentService.query(uuid));
    }
}